﻿#ifndef CALLINGDLL_H
#define CALLINGDLL_H
#include <QDir>
#include <QLibrary>
#include <QDebug>
#include <QCoreApplication>
#include <QDateTime>
#include <QTimer>
#include <string>

#define MAX_DEVICE_COUNT 50 //最大连接设备数
#define MAX_DEVICE_NAME_LENGTH  24//设备名字长度最大值
#define LOAD_FAIL  -6//加载DLL失败
#define FUNCTION_CALL_FAIL  -7//函数调用失败
#define FUNCTION_CALL_TIMEOUT  -8//函数调用超时
#define FEQUEST_FAIL  -9//失败



#define PRODUCT_INDEX_LEN					8
#define POLICE_NUMBER_LEN					7
#define USERNAME_LEN						33
#define COMPANY_CODE_LEN					13
#define COMPANY_NAME_LEN					33

#define VENDOR_CODE_LEN						5
#define DATETIME_LEN						14
#define PASSWD_LEN							6

#define MAX_DATA_LEN						512

typedef char (*pDeviceArray)[MAX_DEVICE_NAME_LENGTH];
class CallingDLL: public QObject
{
public:
  //  QLibrary *TM_C7;
   // QLibrary TCL_C6;
//    QLibrary *TCL_T6;
//     QLibrary *TCL_R1;
//     QLibrary *TCL_3A;
//      QLibrary *TCL_C7;
//    QLibrary *TCL;
//    QLibrary *TCL_S8;
      QLibrary * ZJX_S2;
//    QLibrary *License;
    QString TCLC6;
    QString TMC7;

    struct _SYSTEMTIME {
        quint32 wYear;
        quint32 wMonth;
        quint32 wDayOfWeek;
        quint32 wDay;
        quint32 wHour;
        quint32 wMinute;
        quint32 wSecond;
        quint32 wMilliseconds;
    }SYSTEMTIME;

    struct ZFY_INFO_S8 {
        char cSerial[8];      // 执法记录仪产品序号
        char userNo[7];       // 执法记录仪警员编号
        char userName[33];    // 执法记录仪警员名称
        char unitNo[13];      // 执法记录仪单位编号
        char unitName[33];    // 执法记录仪单位名称

//            ZFY_INFO_S8() {
//                memset(cSerial, 0, sizeof(cSerial));
//                memset(userNo, 0, sizeof(userNo));
//                memset(userName, 0, sizeof(userName));
//                memset(unitNo, 0, sizeof(unitNo));
//                memset(unitName, 0, sizeof(unitName));
//            }
    }ZFYINFOS8;
    struct ZFY_INFO_C7
    {
        char cSerial[8];  // 执法记录仪产品序号，不可为空，等效于C#中的 char[32]
        char userNo[7];   // 执法记录仪使用者警号，不可为空
        char userName[33];// 执法记录仪使用者姓名，管理平台使用警号关联时可为空
        char unitNo[13];  // 执法记录仪使用者单位编号，管理平台使用警号关联时可为空
        char unitName[33];// 执法记录仪使用者单位名称，管理平台使用警号关联时可为空

        // 如果需要在C++中初始化这些字段，可以使用构造函数
//        ZFY_INFO_C7()
//        {
//            std::memset(cSerial, 0, sizeof(cSerial));
//            std::memset(userNo, 0, sizeof(userNo));
//            std::memset(userName, 0, sizeof(userName));
//            std::memset(unitNo, 0, sizeof(unitNo));
//            std::memset(unitName, 0, sizeof(unitName));
//        }
    };
    struct ZFY_INFO
    {
        char  cSerial[PRODUCT_INDEX_LEN];		 /*执法记录仪产品序号，不可为空*/
        char  userNo[POLICE_NUMBER_LEN];         /*执法记录仪使用者警号，不可为空*/
        char  userName[USERNAME_LEN];			 /*执法记录仪使用者姓名，管理系统使用警号关联时可为空*/
        char  unitNo[COMPANY_CODE_LEN];			 /*执法记录仪使用者单位编号，管理系统使用警号关联时可为空*/
        char  unitName[COMPANY_NAME_LEN];		 /*执法记录仪使用者单位名称，管理系统使用警号关联时可为空*/
    }ZFYINFO;

    CallingDLL();
    ~ CallingDLL();
//C7
    int TMUsbInit();
    int TMC7TMUsbInit();
    int TMC7TMdevices(int* count,pDeviceArray* devices_list);
    int TMC7TMconnect(char* const device_name,int* index);//连接指定
    int TMC7TMgetpolicenumByIndex(int index,char* police_num);//获取警员编号
    int TMC7TMgetbatterylevelByIndex(int index,char* police_num);//获取电量值
    int TMC7TMSetTime(int index,_SYSTEMTIME dateTime);//校时
    int TMC7TMGMGetDeviceSN(int index,char* police_num,int* iRet);//获取序列号
    int TMC7TMEntryUMSByIndex(int index);//进入U盘模式
    int TMC7TMdisconnectByIndex(int index);//断开设备 或者 拔出USB时调用

    //C6,C8,C9,S1,C3
    int TCLC6TMUsbInit();
    int TCLC6TMdevices(int* count,pDeviceArray* devices_list);
    int TCLC6TMconnect(char* const device_name,int* index);//连接指定
    int TCLC6TMSetTime(int index,_SYSTEMTIME dateTime); //校时
    int TCLC6TMgetpolicenumByIndex(int index,char* police_num);//获取警员编号
    int TCLC6TMgetbatterylevelByIndex(int index,char* police_num);//获取电量值
    int TCLC6TMGMGetDeviceSN(int index,char* police_num,int* iRet);//获取序列号
    int TCLC6TMEntryUMSByIndex(int index);//进入U盘模式
    int TCLC6TMdisconnectByIndex(int index);//断开设备 或者 拔出USB时调用

//bool TCLS8GetDeviceID(char* const device_name,int* index);
//bool TCLS8ReadDeviceBattery(int* index,int* index1);
    //测试
//    int Decode111(std::string inFileName,std::string key,std::string iv);

//    //T5T6
//    bool TCLT6InitDevice(char* const device_name,int* index);
//    bool TCLT6GetDeviceID(char* const device_name,int* index);
//    bool TCLT6ReadDeviceBattery(int* index,int* iRet);
//    bool TCLT6SetMSDC(char* index,int* iRet);
//    int TCLT6findNewDVSlot(int *index);
//    bool TCLT6GetZFYInfo(ZFY_INFO_S8 *index, char* pwd, int *iRet);
//    bool TCLT6SyncDevTime(char *pwd, int *iRet);
//    bool TCLT6SetMSDC(std::string index, int *iRet);
//    bool TCLT6GetZFYInfo(ZFY_INFO_S8 *index, std::string pwd, int *iRet);

//    //R1R2
//    bool TCLR1GetIDCode(char *cID, unsigned short *usRet);
//    bool  TCLR1Init_Device(char *cID, unsigned short *usRet);
//    bool  TCLR1GetZFYInfo(ZFY_INFO *sZfyInfo, char *cPassword, unsigned short *usRet);
//    bool  TCLR1SyncDevTime(char *cPassword, unsigned short *usRet);
//    bool  TCLR1ReadDeviceBatteryDumpEnergy(int *Battery, char *cPassword, unsigned short *usRet);
//    bool  TCLR1SetMSDC(char *cPassword, unsigned short *usRet);

//    int TCL3AfindNewDVSlot(ushort slot);
//    bool TCL3AGetDeviceID(ushort slot,char *DVSN, int DVSNSize);
//    bool TCL3ASetMSDC(ushort slot);
//    bool TCL3AchkDVPwd(ushort slot, char *DVSN);

//    bool TCLC7Init_Device2(char *IDCode, char *SN, unsigned short *usRet);
//    bool TCLC7GetIDCode2(char *IDCode, char *SN, unsigned short *usRet);
//    bool TCLC7ReadDeviceBatteryDumpEnergy2(int *IDCode, char *SN, char *pwd, unsigned short *usRet);
    //    bool TCLC7SetMSDC2(char *SN, char *pwd, unsigned short *usRet);
    bool ZJXS2ZFY_Connect(int index, char * const device_name);
    bool ZJXS2Init_Device(char *IDCode, unsigned short *iRet);
    bool ZJXS2GetIDCode(char *IDCode, unsigned short *iRet);
    bool ZJXS2SetMSDC(char *sPwd, unsigned short *iRet);
    bool ZJXS2SyncDevTime(char *sPwd, unsigned short *iRet);
    bool ZJXS2ReadDeviceResolution(int *Battery, char *sPwd, unsigned short *iRet);
    int ZJXS2Release_Device();
};

#endif // CALLINGDLL_H
